//
//  WRYLoginTextField.m
//  BaiSiBuJie
//
//  Created by wry on 16/4/29.
//  Copyright © 2016年 WRY. All rights reserved.
//

#import "WRYLoginTextField.h"

@implementation WRYLoginTextField


/*
 1.文本框光标变成白色
 2.文本框开始编辑的时候，文本框占位文字颜色变成白色
 3.当文本框结束编辑，文本框要恢复之前占位文字颜色
 */

-(void)awakeFromNib
{
    [super awakeFromNib];
    
    
    //光标颜色白色
    self.tintColor = [UIColor whiteColor];
    //站位文字颜色亮灰色
    NSMutableDictionary *attr=[NSMutableDictionary dictionary];
    attr[NSForegroundColorAttributeName]=[UIColor lightGrayColor];
    NSAttributedString *attrStr=[[NSAttributedString alloc]initWithString:self.placeholder attributes:attr];
    self.attributedPlaceholder=attrStr;
    
    //添加监听
    [self addTarget:self action:@selector(startEdit) forControlEvents:(UIControlEventEditingDidBegin)];
    
    [self addTarget:self action:@selector(endEdit) forControlEvents:(UIControlEventEditingDidEnd)];
    
    
}

-(void)startEdit
{
    //文本框开始编辑的时候，文本框占位文字颜色变成白色
    NSMutableDictionary *attr=[NSMutableDictionary dictionary];
    attr[NSForegroundColorAttributeName]=[UIColor whiteColor];
    NSAttributedString *attrStr=[[NSAttributedString alloc]initWithString:self.placeholder attributes:attr];
    self.attributedPlaceholder=attrStr;

    
}
-(void)endEdit
{
    //当文本框结束编辑，文本框要恢复之前占位文字颜色
    NSMutableDictionary *attr=[NSMutableDictionary dictionary];
    attr[NSForegroundColorAttributeName]=[UIColor lightGrayColor];
    NSAttributedString *attrStr=[[NSAttributedString alloc]initWithString:self.placeholder attributes:attr];
    self.attributedPlaceholder=attrStr;

}

@end
